package com.margo.project.netty.http;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpRequestDecoder;
import io.netty.handler.codec.http.HttpResponseEncoder;


/**
 * HttpObjectAggregator
 * 当我们用POST方式请求服务器的时候，对应的参数信息是保存在message body中的,如果只是单纯的用HttpServerCodec是无法完全的解析Http POST请求的，
 * 因为HttpServerCodec只能获取uri中参数，所以需要加上HttpObjectAggregator
 * @author fangxingbang
 *
 */
public class MargoChannelInitializer extends ChannelInitializer<SocketChannel>{

	@Override
	protected void initChannel(SocketChannel ch) throws Exception {
		// TODO Auto-generated method stub
		 ChannelPipeline  channelPipeline=ch.pipeline();
		  //http响应编码
		 channelPipeline.addLast("encode",new HttpResponseEncoder());
	        //http请求编码
		 channelPipeline.addLast("decode",new HttpRequestDecoder());
		  //聚合http请求
		 channelPipeline.addLast("aggre",new HttpObjectAggregator(10*1024*1024));
//	        //启用http压缩
//		 channelPipeline.addLast("compressor",new HttpContentCompressor());
		 channelPipeline.addLast("margoServer",new MargoChannelHandle());
	}
}
